#include <iostream>
using namespace std;
const int N = 1e6 + 10;
char a[N];
int n;
char b[N] = { 0 };
int len = 0;
int find(int x) {
    int left = 1, right = len;
    while (left <= right) {
        int mid = left + (right - left) / 2;
        if (b[mid] > x) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    return left;
}
int main() {
    cin >> n;
    cin >> a;
    for (int i = 0; i < n; i++) {
        if (b[len] <= a[i]) {
            b[++len] = a[i];
        } else {
            b[find(a[i])] = a[i];
        }
    }
    cout << n - len << endl;
    return 0;
}